<!--
 * @Descripttion: 
 * @version: 
 * @Author: QYFeng
 * @Date: 2021-05-15 19:12:46
 * @LastEditors: QYFeng
 * @LastEditTime: 2021-05-16 17:06:31
-->
<template>
  <div class="main">
    <!-- 顶部轮播 -->
    <swiper :options="swiperOption">
      <swiper-slide v-for="(item, index) in bannerData" :key="index">
        <a target="_blank" :href="item.url">
          <img :src="item.image" alt="" srcset="" />
        </a>
      </swiper-slide>
    </swiper>
    <div class="center">
      <!-- 推荐 -->
      <div class="block-7">
        <div class="head">
          <div class="lf">推荐</div>
          <!-- <router-link class="rt" to="">
            更多
            <el-image lazy src="../assets/images/jiantou-right.png" alt="" srcset="" />
          </router-link> -->
        </div>
        <div class="body">
          <swiper :options="swiperOptions" class="recommend">
            <swiper-slide v-for="(item, index) in MovieRecommand" :key="index">
              <router-link
                :to="{ name: 'channelDyDetail', query: { id: item.id } }"
              >
                <el-image lazy :src="item.images" alt="" srcset="" />
              </router-link>
            </swiper-slide>
          </swiper>
        </div>
      </div>
      <!-- 广告 -->
      <a target="_blank" :href="adData[0].url" class="ad" v-if="adData[0]">
        <el-image lazy :src="adData[0].image" alt="" srcset="" />
      </a>
      <!-- 明星库 -->
      <div class="block-6">
        <div class="head">
          <div class="lf">明星库</div>
          <router-link class="rt" to="starLibrary">
            更多
            <el-image
              lazy
              src="../assets/images/jiantou-right.png"
              alt=""
              srcset=""
            />
          </router-link>
        </div>
        <div class="body">
          <router-link
            :to="{ name: 'star', query: { name: item.name } }"
            v-for="(item, index) in starListData.slice(0, 12)"
            :key="index"
          >
            <el-image lazy :src="item.image" alt="" srcset="" />
            <h1>{{ item.name }}</h1>
            <p>{{ item.detail }}</p>
          </router-link>
        </div>
      </div>
      <!-- 广告 -->
      <a target="_blank" :href="adData[1].url" class="ad" v-if="adData[1]">
        <el-image lazy :src="adData[1].image" alt="" srcset="" />
      </a>
      <!-- 电影 -->
      <div class="block-5">
        <div class="head">
          <div class="lf">电影</div>
          <router-link class="rt" to="channelDy">
            更多
            <el-image
              lazy
              src="../assets/images/jiantou-right.png"
              alt=""
              srcset=""
            />
          </router-link>
        </div>
        <div class="body">
          <router-link
            :to="{ name: 'channelDyDetail', query: { id: item.id } }"
            v-for="(item, index) in movieData.slice(0, 5)"
            :key="index"
          >
            <div class="img h370">
              <el-image lazy :src="item.images" alt="" srcset="" />
              <div class="time-grade">
                <p class="time">{{ item.duration }}</p>
                <p class="grade">{{ item.score }}</p>
              </div>
            </div>
            <h1>{{ item.name }}</h1>
            <p>{{ item.detail }}</p>
          </router-link>
        </div>
      </div>
      <!-- 广告 -->
      <a target="_blank" :href="adData[2].url" class="ad" v-if="adData[2]">
        <el-image lazy :src="adData[2].image" alt="" srcset="" />
      </a>
      <!-- 电视剧 -->
      <div class="block-5">
        <div class="head">
          <div class="lf">电视剧</div>
          <router-link class="rt" to="channelDsj">
            更多
            <el-image
              lazy
              src="../assets/images/jiantou-right.png"
              alt=""
              srcset=""
            />
          </router-link>
        </div>
        <div class="body">
          <router-link
            :to="{ name: 'channelDsjDetail', query: { id: item.id } }"
            v-for="(item, index) in tvData.slice(0, 5)"
            :key="index"
          >
            <div class="img h370">
              <el-image lazy :src="item.image" alt="" srcset="" />
              <div class="time-grade">
                <p class="time">{{ item.duration }}</p>
                <p class="grade">{{ item.score }}</p>
              </div>
            </div>
            <h1>{{ item.name }}</h1>
            <p>{{ item.detail }}</p>
          </router-link>
        </div>
      </div>
      <!-- 广告 -->
      <a target="_blank" :href="adData[3].url" class="ad" v-if="adData[3]">
        <el-image lazy :src="adData[3].image" alt="" srcset="" />
      </a>
      <!-- 综艺 -->
      <div class="block-5">
        <div class="head">
          <div class="lf">综艺</div>
          <router-link class="rt" to="channelZy">
            更多
            <el-image
              lazy
              src="../assets/images/jiantou-right.png"
              alt=""
              srcset=""
            />
          </router-link>
        </div>
        <div class="body">
          <router-link
            :to="{ name: 'channelZyDetail', query: { id: item.id } }"
            v-for="(item, index) in varietyData.slice(0, 10)"
            :key="index"
          >
            <div class="img h197">
              <el-image lazy :src="item.images" alt="" srcset="" />
              <div class="time-grade">
                <p class="time">{{ item.duration }}</p>
                <p class="grade">{{ item.score }}</p>
              </div>
            </div>
            <h1>{{ item.name }}</h1>
            <p>{{ item.detail }}</p>
          </router-link>
        </div>
      </div>
      <!-- 广告 -->
      <a target="_blank" :href="adData[4].url" class="ad" v-if="adData[4]">
        <el-image lazy :src="adData[4].image" alt="" srcset="" />
      </a>
      <!-- 动漫 -->
      <div class="block-5">
        <div class="head">
          <div class="lf">动漫</div>
          <router-link class="rt" to="channelDm">
            更多
            <el-image
              lazy
              src="../assets/images/jiantou-right.png"
              alt=""
              srcset=""
            />
          </router-link>
        </div>
        <div class="body">
          <router-link
            :to="{ name: 'channelDmDetail', query: { id: item.id } }"
            v-for="(item, index) in dmData.slice(0, 10)"
            :key="index"
          >
            <div class="img h197">
              <el-image lazy :src="item.image" alt="" srcset="" />
              <div class="time-grade">
                <p class="time">{{ item.duration }}</p>
                <p class="grade">{{ item.score }}</p>
              </div>
            </div>
            <h1>{{ item.name }}</h1>
            <p>{{ item.detail }}</p>
          </router-link>
        </div>
      </div>
      <!-- 广告 -->
      <a target="_blank" :href="adData[5].url" class="ad" v-if="adData[5]">
        <el-image lazy :src="adData[5].image" alt="" srcset="" />
      </a>
      <!-- 短片 -->
      <div class="block-5">
        <div class="head">
          <div class="lf">短片</div>
          <router-link class="rt" to="channelDp">
            更多
            <el-image
              lazy
              src="../assets/images/jiantou-right.png"
              alt=""
              srcset=""
            />
          </router-link>
        </div>
        <div class="body">
          <router-link :to="{ name: 'channelDpDetail', query: { id: item.id } }" v-for="(item, index) in dpData.slice(0,5)" :key="index">
            <div class="img h370">
              <el-image
                lazy
                :src="item.image"
                alt=""
                srcset=""
              />
              <div class="time-grade">
                <p class="time">{{ item.duration }}</p>
                <p class="grade">{{ item.score }}</p>
              </div>
            </div>
            <h1>{{ item.name }}</h1>
            <p>{{ item.detail }}</p>
          </router-link>
        </div>
      </div>
      <!-- 广告 -->
      <a target="_blank" :href="adData[6].url" class="ad" v-if="adData[6]">
        <el-image lazy :src="adData[6].image" alt="" srcset="" />
      </a>
      <!-- 纪录片 -->
      <div class="block-5">
        <div class="head">
          <div class="lf">纪录片</div>
          <router-link class="rt" to="channelJlp">
            更多
            <el-image
              lazy
              src="../assets/images/jiantou-right.png"
              alt=""
              srcset=""
            />
          </router-link>
        </div>
        <div class="body">
          <router-link :to="{ name: 'channelJlpDetail', query: { id: item.id } }" v-for="(item, index) in jlData.slice(0,5)" :key="index">
            <div class="img h370">
              <el-image
                lazy
                :src="item.image"
                alt=""
                srcset=""
              />
              <div class="time-grade">
                <p class="time">{{ item.duration }}</p>
                <p class="grade">{{ item.score }}</p>
              </div>
            </div>
            <h1>{{ item.name }}</h1>
            <p>{{ item.detail }}</p>
          </router-link>
        </div>
      </div>
      <!-- 广告 -->
      <a target="_blank" :href="adData[7].url" class="ad" v-if="adData[7]">
        <el-image lazy :src="adData[7].image" alt="" srcset="" />
      </a>
      <!-- 音乐 -->
      <div class="block-6">
        <div class="head">
          <div class="lf">音乐</div>
          <router-link class="rt" to="album">
            更多
            <el-image
              lazy
              src="../assets/images/jiantou-right.png"
              alt=""
              srcset=""
            />
          </router-link>
        </div>
        <div class="body">
          <router-link
            :to="{ name: 'album', query: { id: item.id } }"
            v-for="(item, index) in musicListData.slice(0, 12)"
            :key="index"
          >
            <el-image lazy :src="item.image" alt="" srcset="" />
            <h1>{{ item.name }}</h1>
            <p>{{ item.singer }}</p>
          </router-link>
        </div>
      </div>
      <!-- 广告 -->
      <a target="_blank" :href="adData[8].url" class="ad" v-if="adData[8]">
        <el-image lazy :src="adData[8].image" alt="" srcset="" />
      </a>
      <!-- 娱乐资讯 -->
      <div class="block-6">
        <div class="head">
          <div class="lf">娱乐资讯</div>
          <router-link class="rt" to="news">
            更多
            <el-image
              lazy
              src="../assets/images/jiantou-right.png"
              alt=""
              srcset=""
            />
          </router-link>
        </div>
        <div class="body">
          <router-link
            :to="{ name: 'newsDetail', query: { id: item.id } }"
            v-for="(item, index) in newsData.slice(0, 12)"
            :key="index"
          >
            <el-image lazy :src="item.image" alt="" srcset="" />
            <h1>{{ item.title }}</h1>
            <p>{{ item.create_time }}</p>
          </router-link>
        </div>
      </div>
      <!-- 广告 -->
      <a target="_blank" :href="adData[9].url" class="ad" v-if="adData[9]">
        <el-image lazy :src="adData[9].image" alt="" srcset="" />
      </a>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 顶部轮播图设置
      swiperOption: {
        autoplay: {
          disableOnInteraction: false, // 用户操作swiper之后，是否禁止autoplay
          delay: 5000, // 自动切换的时间间隔（单位ms）
        },
        // loop: true,
      },
      // 推荐设置
      swiperOptions: {
        slidesPerView: 7,
        spaceBetween: 20,
        freeMode: true,
      },
      bannerData: [], // 顶部导航
      MovieRecommand: [], // 推荐
      adData: [], // 广告
      movieData: [], // 电影
      tvData: [], // 电视剧
      varietyData: [], // 综艺
      musicListData: [], // 音乐
      newsData: [], // 资讯
      starListData: [], // 明星库
      dmData: [], // 动漫
      dpData:[], //短片
      jlData:[] //纪录片
    };
  },
  created() {
    // 顶部轮播
    this.$http.getBanner().then((res) => {
      if (res.data.code === 0) {
        this.bannerData = res.data.data;
      } else {
        this.$message.error("获取失败，请重试！");
      }
    });
    // 推荐
    this.$http.getMovieRecommand().then((res) => {
      if (res.data.code === 0) {
        this.MovieRecommand = res.data.data;
      } else {
        this.$message.error("获取失败，请重试！");
      }
    });
    // 广告
    this.$http.getAd().then((res) => {
      if (res.data.code === 0) {
        this.adData = res.data.data;
      } else {
        this.$message.error("获取失败，请重试！");
      }
    });
    // 电影
    this.$http.getMovie().then((res) => {
      if (res.data.code === 0) {
        this.movieData = res.data.data;
      } else {
        this.$message.error("获取失败，请重试！");
      }
    });
    // 电视剧
    this.$http.getTv().then((res) => {
      if (res.data.code === 0) {
        this.tvData = res.data.data;
      } else {
        this.$message.error("获取失败，请重试！");
      }
    });
    // 综艺
    this.$http.getVariety().then((res) => {
      if (res.data.code === 0) {
        this.varietyData = res.data.data;
      } else {
        this.$message.error("获取失败，请重试！");
      }
    });
    //音乐
    this.$http.getMusicList().then((res) => {
      if (res.data.code === 0) {
        this.musicListData = res.data.data;
      } else {
        this.$message.error("获取失败，请重试！");
      }
    });
    //资讯
    this.$http.getNews().then((res) => {
      if (res.data.code === 0) {
        this.newsData = this.newsData.concat(res.data.data);
      } else {
        this.$message.error("获取失败，请重试！");
      }
    });
    //明星库
    this.$http.getStarList().then((res) => {
      if (res.data.code === 0) {
        this.starListData = res.data.data;
      } else {
        this.$message.error("获取失败，请重试！");
      }
    });
    // 动漫
    this.$http.getMovie({ attitude: "动画" }).then((res) => {
      if (res.data.code === 0) {
        this.dmData = res.data.data;
      } else {
        this.$message.error("获取失败，请重试！");
      }
    });
    // 短片
    this.$http.getMovie({ attitude: "短片" }).then((res) => {
      if (res.data.code === 0) {
        this.dpData = res.data.data;
      } else {
        this.$message.error("获取失败，请重试！");
      }
    });
    // 纪录片
    this.$http.getMovie({ attitude: "纪录片" }).then((res) => {
      if (res.data.code === 0) {
        this.jlData = res.data.data;
      } else {
        this.$message.error("获取失败，请重试！");
      }
    });
  },
  methods: {},
};
</script>

<style lang="scss" scoped>
.h370 {
  height: 370px;
}
.h197 {
  height: 197px;
}
.el-carousel,
.el-carousel__item {
  height: 700px;
  .el-image {
    width: 100%;
    height: 100%;
  }
}
.center {
  width: 1600px;
  margin: 0 auto;
  padding-bottom: 100px;
  .block-7 {
    margin-top: 80px;
    margin-bottom: 40px;
    .head {
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: 45px;
      .lf {
        font-size: 20px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #333333;
      }
      .rt {
        height: 45px;
        display: flex;
        align-items: center;
        font-size: 16px;
        font-family: PingFang SC;
        font-weight: 400;
        line-height: 40px;
        color: #666666;
        .el-image {
          width: 14.85px;
          height: 25.46px;
          margin-left: 10px;
        }
      }
    }
    .body {
      margin-top: 20px;
      height: 140px;
      a {
        display: inline-block;
        width: 210px;
        height: 140px;
        border-radius: 10px;
        overflow: hidden;
        .el-image {
          width: 100%;
          height: 100%;
        }
      }
    }
  }
  .ad {
    display: inline-block;
    height: 200px;
    width: 1600px;
    .el-image {
      height: 100%;
      width: 100%;
      border-radius: 20px;
    }
  }
  .block-6 {
    margin-top: 80px;
    .head {
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: 45px;
      .lf {
        font-size: 20px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #333333;
      }
      .rt {
        height: 45px;
        display: flex;
        align-items: center;
        font-size: 16px;
        font-family: PingFang SC;
        font-weight: 400;
        line-height: 40px;
        color: #666666;
        .el-image {
          width: 14.85px;
          height: 25.46px;
          margin-left: 10px;
        }
      }
    }
    .body {
      display: flex;
      flex-wrap: wrap;
      margin-top: 20px;
      a {
        display: inline-block;
        width: 246px;
        margin-bottom: 40px;
        .el-image {
          width: 246px;
          height: 164px;
          border-radius: 10px;
        }
        h1 {
          font-size: 20px;
          font-family: PingFang SC;
          font-weight: 400;
          color: #333333;
          text-align: right;
          margin: 10px 0;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        p {
          font-size: 16px;
          font-family: PingFang SC;
          font-weight: 400;
          line-height: 22px;
          color: #999999;
          text-align: right;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
      a:not(:nth-child(6n)) {
        margin-right: 24px;
      }
    }
  }
  .block-5 {
    margin-top: 80px;
    .head {
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: 45px;
      .lf {
        font-size: 20px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #333333;
      }
      .rt {
        height: 45px;
        display: flex;
        align-items: center;
        font-size: 16px;
        font-family: PingFang SC;
        font-weight: 400;
        line-height: 40px;
        color: #666666;
        .el-image {
          width: 14.85px;
          height: 25.46px;
          margin-left: 10px;
        }
      }
    }
    .body {
      display: flex;
      flex-wrap: wrap;
      margin-top: 20px;
      a {
        display: inline-block;
        width: 295px;
        margin-bottom: 40px;
        .img {
          position: relative;
          .time-grade {
            width: 100%;
            position: absolute;
            left: 0;
            bottom: 15px;
            padding-left: 10px;
            padding-right: 30px;
            display: flex;
            justify-content: space-between;
            font-family: PingFang SC;
            font-weight: 400;
            .tiem {
              font-size: 20px;
              color: #f5f5f5;
            }
            .grade {
              font-size: 22px;
              color: #ff6f00;
            }
          }
          .el-image {
            width: 100%;
            height: 100%;
            border-radius: 10px;
          }
        }
        h1 {
          font-size: 20px;
          font-family: PingFang SC;
          font-weight: 400;
          color: #333333;
          text-align: right;
          margin: 10px 0;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        p {
          font-size: 16px;
          font-family: PingFang SC;
          font-weight: 400;
          line-height: 22px;
          color: #999999;
          text-align: right;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .time {
          color: #fff;
        }
      }
      a:not(:nth-child(5n)) {
        margin-right: 31px;
      }
    }
  }
}
::v-deep {
  .swiper-container {
    height: 700px;
    width: 100%;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .recommend {
    background: none;
    height: 140px;
    .swiper-container,
    .swiper-slide {
      height: 140px;
    }
  }
}
</style>
